﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SSN.Utilities.Database;
using SSN.Utilities.Cache;
using SSN.Utilities.Security;

namespace SSN.WebFramework
{
    public class StaticFileManager
    {

        private static ListCache<StaticFile> _fileCache = new ListCache<StaticFile>(_initFileCache, new TimeSpan(0, 1, 0));

        private static List<StaticFile> _initFileCache()
        {
            SystemSecurityContext sysCtx = new SystemSecurityContext();
            return StaticFile.DatabaseType.CreateListFromQuery<StaticFile>(sysCtx, string.Format("SELECT * FROM {0}", StaticFile.TableName));
        }

        public List<StaticFile> RecentlyUpdatedDocuments()
        {
            return (from f in _fileCache.AllItems where f.Visible orderby f.LastUpdated descending select f).Take(5).ToList();
        }
    }
}
